var Toast = require('../../utils/toast.js');
Page({
  data: {
    currentTab: '0',
    givefrined: 0,
    giveTab: [1, 2, 5, 10, 20, 50],
    show: false,
    giveShow: false,
    showMenu: false,
    showCollection: false,
    followShow: false,
    isFollow: false, //是否已关注
    unFollowshow: false, //取消关注弹窗
    consultShow: false, //咨询弹窗
    unCollectionshow: false,
    computeCount: 1,
    totalPrice: 0,
    curPrice: 99.99
  },
  onLoad: function() {
    let totalPrice = parseFloat(this.data.curPrice * this.data.computeCount).toFixed(2)
    this.setData({
      totalPrice: totalPrice
    })
  },
  swichNav(e) {
    let that = this
    if (this.data.currentTab === e.target.dataset.current) {
      return false
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    console.log(this.data.currentTab)
  },
  buy() {
    this.setData({
      showMenu: true
    })
  },
  closeBuy() {
    this.setData({
      showMenu: false
    })
  },
  chooseCount(e) {
    let id = e.currentTarget.dataset.id
    let count = e.currentTarget.dataset.count
    let price = parseFloat(count * this.data.curPrice).toFixed(2)
    if (id) {
      this.setData({
        givefrined: id,
        computeCount: count,
        totalPrice: price
      })
    }
  },
  giveOpen(e) {
    this.setData({
      giveShow: true
    })
  },
  giveClose(e) {
    this.setData({
      giveShow: false
    })
  },
  minus(e) {
    let count = e.currentTarget.dataset.count;
    count--;
    let price = parseFloat(count * this.data.curPrice).toFixed(2)
    if (count < 1) {
      Toast('最少选择一个送给好友', 'noicon');
      return
    } else {
      this.setData({
        computeCount: count,
        totalPrice: price,
        givefrined: 6
      })
    }
  },
  plus(e) {
    let count = e.currentTarget.dataset.count;
    count++;
    let price = parseFloat(count * this.data.curPrice).toFixed(2)
    this.setData({
      computeCount: count,
      totalPrice: price,
      givefrined: 6
    })
  },
  giveBtn(e) {
    let count = e.currentTarget.dataset.count;
    let totalprice = e.currentTarget.dataset.totalprice;
    console.log(count)
    console.log(totalprice)
    Toast('赠送成功！', 'success');
    this.setData({
      giveShow: false
    })
  },
  //收藏
  collection(e) {
    if (!this.data.showCollection) {
      this.setData({
        showCollection: true
      })
    } else {
      this.setData({
        unCollectionshow: true
      })
    }
  },
  //不再收藏
  noCollection() {
    this.setData({
      unCollectionshow: false,
      showCollection: false
    })
  },
  closeCollection() {
    this.setData({
      unCollectionshow: false
    })
  },
  //关注弹窗
  follow() {
    this.setData({
      followShow: true
    })
  },
  //去关注
  toFollow() {
    this.setData({
      followShow: false,
      isFollow: true
    })
  },
  closeFollow() {
    this.setData({
      followShow: false
    })
  },
  //取消关注弹窗
  unFollow() {
    this.setData({
      unFollowshow: true
    })
  },
  //取消关注功能
  noFollow() {
    this.setData({
      unFollowshow: false,
      isFollow: false
    })
  },
  //取消关注关闭弹窗
  closeComment() {
    this.setData({
      unFollowshow: false
    })
  },
  consultation() {
    this.setData({
      consultShow: true
    })
  },
  closeConsult() {
    this.setData({
      consultShow: false
    })
  },
  sendConsult() {
    this.setData({
      consultShow: false
    })
  }
})